using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
    public class ContrControl
    {
		#region Local Variable
        private ContrDataAccess _ContrDAO;
		#endregion Local Variable
		
		#region Method
        public ContrControl()
        {
            _ContrDAO = new ContrDataAccess();
        }
		
        public ContrInfo Get_Contr(
			String Contract,
			Int32 aYear
		, ref string sErr)
        {
            return _ContrDAO.Get_Contr(
			Contract,
			aYear
			, ref sErr);
        }
		
        public DataTable GetAll_Contr(ref string sErr)
        {
            return _ContrDAO.GetAll_Contr(ref sErr);
        }

        public DataTable GetAll_Contr1(ref string sErr)
        {
            return _ContrDAO.GetAll_Contr1(ref sErr);
        }

        public DataTable GetAll_bgGroup(ref string sErr)
        {
            return _ContrDAO.GetAll_bgGroup(ref sErr);
        }

        public DataTable GetAll_bgGroup1(ref string sErr)
        {
            return _ContrDAO.GetAll_bgGroup1(ref sErr);
        }

        public DataTable GetCond(String strCond, ref string sErr)
        {
            return _ContrDAO.GetCond(strCond, ref sErr);
        }

        public DataTable GetCond1(String strCond, ref string sErr)
        {
            return _ContrDAO.GetCond1(strCond, ref sErr);
        }

        public DataTable GetTotal(String strCond, ref string sErr)
        {
            return _ContrDAO.GetTotal(strCond, ref sErr);
        }

        public DataTable GetTotal1(String strCond, ref string sErr)
        {
            return _ContrDAO.GetTotal1(strCond, ref sErr);
        }
		
        public Int32 Add_Contr(ContrInfo obj, ref string sErr)
        {
            return _ContrDAO.Add_Contr(obj, ref sErr);
        }
        public Int32 Add_Contr1(ContrInfo obj, ref string sErr)
        {
            return _ContrDAO.Add_Contr1(obj, ref sErr);
        }
		
        public string Update_Contr(ContrInfo obj)
        {
            return _ContrDAO.Update_Contr(obj);
        }
        public string Update_Contr1(ContrInfo obj)
        {
            return _ContrDAO.Update_Contr1(obj);
        }

        public string Update_Shared(ContrInfo obj)
        {
            return _ContrDAO.Update_Shared(obj);
        }

        public Boolean IsExist_GroupOtherShared(
            String Contract,
            Int32 aYear,
            String BudgetGroup,
            Int16 SharedBudget
        )
        {
            return _ContrDAO.IsExist_GroupOtherShared(Contract, aYear, BudgetGroup, SharedBudget);
        }

        public Boolean IsExist_GroupOtherShared1(
            String Contract,
            Int32 aYear,
            String BudgetGroup,
            Int16 SharedBudget
        )
        {
            return _ContrDAO.IsExist_GroupOtherShared1(Contract, aYear, BudgetGroup, SharedBudget);
        }
		
        public string Delete_Contr(
			String Contract,
			Int32 aYear
		)
        {
            return _ContrDAO.Delete_Contr(
			Contract,
			aYear
			);
        }
        public string Delete_Contr1(
            String Contract,
            Int32 aYear
        )
        {
            return _ContrDAO.Delete_Contr1(
            Contract,
            aYear
            );
        }  
        public Boolean IsExist_Contr(
			String Contract,
			Int32 aYear
		)
        {
            return _ContrDAO.IsExist_Contr(
			Contract,
			aYear
			);
        }
        public Boolean IsExist_Contr1(
            String Contract,
            Int32 aYear
        )
        {
            return _ContrDAO.IsExist_Contr1(
            Contract,
            aYear
            );
        } 
		
      /*  public string Delete_Contr(String arrID)
        {
            string kq = "";
            string[] arrStrID = arrID.Split(',');
            foreach (string strID in arrStrID)
            {
                if (strID != "")
                {
                    int ID = Convert.ToInt32(strID);
                    kq += _ContrDAO.Delete_Contr(ID);
                }
            }
            return kq;
        } */
		        
        public DataTable Search(String columnName, String columnValue, String condition, ref String sErr)
        {           
            return _ContrDAO.Search(columnName, columnValue, condition, ref  sErr);
        }

        public string InsertUpdate(ContrInfo obj)
        {
            string sErr = "";
            if (IsExist_Contr(
            obj.Contract, obj.aYear
            ))
            {
                sErr = Update_Contr(obj);
            }
            else
                Add_Contr(obj, ref sErr);
            return sErr;
        }

        public string InsertUpdate1(ContrInfo obj)
        {
            string sErr = "";
            if (IsExist_Contr1(
            obj.Contract, obj.aYear
            ))
            {
                sErr = Update_Contr1(obj);
            }
            else
                Add_Contr1(obj, ref sErr);
            return sErr;
        }
        
        public string TransferIn(DataRow row)
        {
            ContrInfo inf = new ContrInfo(row);
            return InsertUpdate(inf);
        }

        public string TransferIn1(DataRow row)
        {
            ContrInfo inf = new ContrInfo(row);
            return InsertUpdate1(inf);
        }

        public string Contr_getSumAmt(
            String Contract,
            Int32 aYear
        )
        {
            return _ContrDAO.Contr_getSumAmt(
            Contract,
            aYear
            );
        }

        public string Contr_getSumAmt1(
            String Contract,
            Int32 aYear
        )
        {
            return _ContrDAO.Contr_getSumAmt1(
            Contract,
            aYear
            );
        }
        
		#endregion Method

    }
}
